package com.sskj.lib.util;

import android.graphics.Bitmap;

import com.sskj.lib.base.MyApplication;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.WXImageObject;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXTextObject;
import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;

public class WXShareUtil {


    /**
     * 分享微信好友
     * （分享链接）
     */
    private void shareCodeFriends(String title, String description) {
        WXWebpageObject webpage = new WXWebpageObject();
        webpage.webpageUrl = "";
        //用WXWebpageObject初始化一个WXMediaMessage对象
        WXMediaMessage message = new WXMediaMessage(webpage);
        message.title = title;
        message.description = description;
//        Bitmap thumb = BitmapFactory.decodeResource(getResources(), R.drawable.redbook_icons);
//        message.thumbData = Util.bmpToByteArray(thumb, true);
        //构造一个Req
        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = String.valueOf(System.currentTimeMillis());
        req.message = message;
        req.scene = SendMessageToWX.Req.WXSceneSession;
        //调用api接口发送数据到微信
        MyApplication.iwxapi.sendReq(req);
    }

    public static void shareFriendsTv(String text) {
        //初始化一个 WXTextObject 对象，填写分享的文本内容
        WXTextObject textObj = new WXTextObject();
        textObj.text = text;

        //用 WXTextObject 对象初始化一个 WXMediaMessage 对象
        WXMediaMessage msg = new WXMediaMessage();
        msg.mediaObject = textObj;
        msg.description = text;

        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = String.valueOf(System.currentTimeMillis());
        req.message = msg;
        req.scene = SendMessageToWX.Req.WXSceneSession;
        //调用api接口，发送数据到微信
        MyApplication.iwxapi.sendReq(req);
    }

    public static void shareQuanTv(String text) {
        //初始化一个 WXTextObject 对象，填写分享的文本内容
        WXTextObject textObj = new WXTextObject();
        textObj.text = text;

        //用 WXTextObject 对象初始化一个 WXMediaMessage 对象
        WXMediaMessage msg = new WXMediaMessage();
        msg.mediaObject = textObj;
        msg.description = text;

        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = String.valueOf(System.currentTimeMillis());
        req.message = msg;
        req.scene = SendMessageToWX.Req.WXSceneTimeline;
        //调用api接口，发送数据到微信
        MyApplication.iwxapi.sendReq(req);
    }

    /**
     * 图片
     * 分享微信好友
     */
    public static void shareFriendsBitmap(Bitmap bitmap) {
        WXImageObject wximg = new WXImageObject(bitmap);
        WXMediaMessage message = new WXMediaMessage();
        message.mediaObject = wximg;
        //构造一个Req
        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = String.valueOf(System.currentTimeMillis());
        req.message = message;
        req.scene = SendMessageToWX.Req.WXSceneSession;
        //调用api接口发送数据到微信
        MyApplication.iwxapi.sendReq(req);
    }

    /**
     * 图片
     * 分享微信朋友圈
     */
    public static void shareQuanBitmap(Bitmap bitmap) {
        WXImageObject wximg = new WXImageObject(bitmap);
        WXMediaMessage message = new WXMediaMessage();
        message.mediaObject = wximg;
        //构造一个Req
        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = String.valueOf(System.currentTimeMillis());
        req.message = message;
        req.scene = SendMessageToWX.Req.WXSceneTimeline;
        //调用api接口发送数据到微信
        MyApplication.iwxapi.sendReq(req);
    }


}
